import qrcode
import PIL
import base64
import binascii


def make_text_qrcode(text) -> PIL.Image:
    qr = qrcode.QRCode(version=1, error_correction=qrcode.ERROR_CORRECT_L, box_size=10, border=2)
    qr.add_data(text)
    qr.make(fit=True)
    return qr.make_image()


if __name__ == "__main__":
    # A总数|页码|分页CRC[|文件CRC|文件名]|内容
    data1 = b"ABC"
    data2 = b"DEF"
    filename = "1.txt"
    crc1 = binascii.crc32(data1)
    crc2 = binascii.crc32(data2)
    crc = binascii.crc32(data1 + data2)
    qr = make_text_qrcode((f"A2|0|{crc1:X}|{crc:X}|{filename}|").encode()+base64.b64encode(data1))
    qr.show()
    qr = make_text_qrcode((f"A2|1|{crc2:X}|").encode()+base64.b64encode(data2))
    qr.show()
